package com.ia.aistream.controller.dxfcomponent;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import com.ia.aistream.common.annotation.Log;
import com.ia.aistream.common.config.Global;
import com.ia.aistream.common.utils.StringUtils;
import com.ia.aistream.common.utils.file.FileUtils;
import com.ia.aistream.model.dxfcomponent.entity.DrawDxfComp;
import com.ia.aistream.service.dxfcomponent.IDxfDrawService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
//import com.ia.aistream.common.annotation;
import com.ia.aistream.common.enums.BusinessType;
import com.ia.aistream.model.dxfcomponent.entity.DxfComponent;
import com.ia.aistream.service.dxfcomponent.IDxfComponentService;
import com.ia.aistream.common.core.controller.BaseController;
import com.ia.aistream.common.core.domain.AjaxResult;
import com.ia.aistream.common.utils.poi.ExcelUtil;
import com.ia.aistream.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * dxf文件部件Controller
 * 
 * @author ymj
 * @date 2020-12-04
 */
@Controller
@RequestMapping("/dxfcomponent/component")
public class DxfComponentController extends BaseController
{
    private String prefix = "dxfcomponent/component";

    @Autowired
    private IDxfComponentService dxfComponentService;
//    @Autowired
//    private IDxfDrawService dxfDrawService;

    @RequiresPermissions("dxfcomponent:component:view")
    @GetMapping()
    public String component()
    {
        return prefix + "/component";
    }

    /**
     * 查询dxf文件部件列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DrawDxfComp DrawDxfComp)
    {
        List<DrawDxfComp> list = new ArrayList<>();

        if(DrawDxfComp.getSystem()!=null && !DrawDxfComp.getSystem().equals("")){
            list = dxfComponentService.selectDrawDxfCompList(DrawDxfComp);
        }
        return getDataTable(list);
    }

    /***
     * 实现设备信息的圈定
     * 将转化后的PDF文件返回界面显示
     * @param componentId
     * @param mmap
     * @return
     */
    @GetMapping("/circle")
    public String drawCircle(Long componentId, ModelMap mmap)  throws Exception
    {
        String s = dxfComponentService.drawCircleService(componentId);
        mmap.put("drawPdf", s);
        return prefix + "/view";
    }
    /***
     * 调用Java服务
     * @param componentId
     * @param mmap
     * @return
     */
    @GetMapping("/twoCircle")
    public String drawCircleToJava(Long componentId, ModelMap mmap)  throws Exception
    {
        String s = dxfComponentService.drawCircleService(componentId);
        mmap.put("drawPdf", s);
        return prefix + "/view";
    }
    /**
     * 新增dxf文件部件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存dxf文件部件
     */
    @Log(title = "dxf文件部件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DxfComponent dxfComponent)
    {
        return toAjax(dxfComponentService.insertDxfComponent(dxfComponent));
    }

    /**
     * 修改dxf文件部件
     */
    @GetMapping("/edit/{componentId}")
    public String edit(@PathVariable("componentId") Long componentId, ModelMap mmap)
    {
        DxfComponent dxfComponent = dxfComponentService.selectDxfComponentById(componentId);
        mmap.put("dxfComponent", dxfComponent);
        return prefix + "/edit";
    }

    /**
     * 修改保存dxf文件部件
     */
    @Log(title = "dxf文件部件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DxfComponent dxfComponent)
    {
        return toAjax(dxfComponentService.updateDxfComponent(dxfComponent));
    }

    /**
     * 删除dxf文件部件
     */
    @Log(title = "dxf文件部件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dxfComponentService.deleteDxfComponentByIds(ids));
    }

}
